Skip to content

ZOOKEEPER-5021: Exit from zkCli when interrupt (Ctrl-C) or EOF (Ctrl-D) is pressed#2369

Merged
anmolnar merged 2 commits intoapache:masterfrom
PDavid:ZOOKEEPER-5021-cli-fix-eof-interrupt-2
Apr 9, 2026
Merged

ZOOKEEPER-5021: Exit from zkCli when interrupt (Ctrl-C) or EOF (Ctrl-D) is pressed#2369
anmolnar merged 2 commits intoapache:masterfrom
PDavid:ZOOKEEPER-5021-cli-fix-eof-interrupt-2

Conversation

@PDavid
Copy link
Copy Markdown
Contributor

@PDavid PDavid commented Mar 31, 2026

Problem

Closing the input stream for a terminal by pressing "Ctrl-D" should automatically exit the interactive shell, but the bin/zkCli.sh does not exit, but does disable JLine support, leaving you at a prompt-less terminal. Pressing "Ctrl-D" a second time exited correctly, and so did entering "quit" (without JLine support enabled).

Cause

After the JLine 3.x upgrade, pressing Ctrl-C or Ctrl-D results in InvocationTargetException which we caught and set the jlinemissing flag to true to fall back to the promptless shell.

Fix

Set jlinemissing flag to true initially and only set it to false when we were able to load JLine classes. This way we will not end up in the promptless shell.

…D) is pressed

Problem

Closing the input stream for a terminal by pressing "Ctrl-D" should
automatically exit the interactive shell, but the bin/zkCli.sh does
not exit, but does disable JLine support, leaving you at a prompt-less
terminal. Pressing "Ctrl-D" a second time exited correctly, and so did
entering "quit" (without JLine support enabled).

Cause

After the JLine 3.x upgrade, pressing Ctrl-C or Ctrl-D results in InvocationTargetException which we caught and set the jlinemissing flag to true to fall back to the promptless shell.

Fix

Set jlinemissing flag to true initially and only set it to false when we were able to load JLine classes. This way we will not end up in the promptless shell.
@PDavid
Copy link
Copy Markdown
Contributor Author

PDavid commented Mar 31, 2026

Testing

Built the project with mvn clean install -DskipTests
Set up config: cp conf/zoo_sample.cfg conf/zoo.cfg
Started ZooKeeper server: bin/zkServer.sh start
Started the ZK CLI: bin/zkCli.sh -server 127.0.0.1:2181

After this fix pressing a Ctrl-D (or Ctrl-C) one time should exit the ZK shell (and should not print "JLine support is disabled" and drop you into prompltess shell where you have to Ctrl-D / Ctrl-C again).

$ bin/zkCli.sh -server 127.0.0.1:2181

...

2026-03-31 10:33:37,587 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:java.library.path=/usr/java/packages/lib:/usr/lib64:/lib64:/lib:/usr/lib
2026-03-31 10:33:37,587 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:java.io.tmpdir=/tmp
2026-03-31 10:33:37,587 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:java.compiler=<NA>
2026-03-31 10:33:37,587 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:os.name=Linux
2026-03-31 10:33:37,587 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:os.arch=amd64
2026-03-31 10:33:37,587 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:os.version=6.17.0-19-generic
2026-03-31 10:33:37,587 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:user.name=david
2026-03-31 10:33:37,587 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:user.home=/home/david
2026-03-31 10:33:37,587 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:user.dir=/home/david/projects/upstream/zookeeper
2026-03-31 10:33:37,587 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:jvm.memory.free=232MB
2026-03-31 10:33:37,587 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:jvm.memory.max=256MB
2026-03-31 10:33:37,587 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:jvm.memory.total=256MB
2026-03-31 10:33:37,588 [myid:] - INFO  [main:o.a.z.ZooKeeper@1123] - Initiating client connection, connectString=127.0.0.1:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@f8c1ddd
2026-03-31 10:33:37,591 [myid:] - INFO  [main:o.a.z.c.X509Util@85] - Setting -D jdk.tls.rejectClientInitiatedRenegotiation=true to disable client-initiated TLS renegotiation
2026-03-31 10:33:37,686 [myid:] - INFO  [main:o.a.z.c.X509Util@109] - Default TLS protocol is TLSv1.3, supported TLS protocols are [TLSv1.3, TLSv1.2, TLSv1.1, TLSv1, SSLv3, SSLv2Hello]
2026-03-31 10:33:37,688 [myid:] - INFO  [main:o.a.z.c.HostConnectionManager@127] - HostConnectionManager initialized with 1 servers
2026-03-31 10:33:37,691 [myid:] - INFO  [main:o.a.z.ClientCnxnSocket@235] - jute.maxbuffer value is 1048575 Bytes
2026-03-31 10:33:37,694 [myid:] - INFO  [main:o.a.z.ClientCnxn@1723] - zookeeper.request.timeout value is 0. feature enabled=false
Welcome to ZooKeeper!
JLine support is enabled
2026-03-31 10:33:37,698 [myid:127.0.0.1:2181] - INFO  [main-SendThread(127.0.0.1:2181):o.a.z.ClientCnxn$SendThread@1154] - Opening socket connection to server /127.0.0.1:2181.
2026-03-31 10:33:37,698 [myid:127.0.0.1:2181] - INFO  [main-SendThread(127.0.0.1:2181):o.a.z.ClientCnxn$SendThread@1156] - SASL config status: Will not attempt to authenticate using SASL (unknown error)
2026-03-31 10:33:37,703 [myid:127.0.0.1:2181] - INFO  [main-SendThread(127.0.0.1:2181):o.a.z.ClientCnxn$SendThread@1007] - Socket connection established, initiating session, client: /127.0.0.1:46710, server: /127.0.0.1:2181
2026-03-31 10:33:37,709 [myid:127.0.0.1:2181] - INFO  [main-SendThread(127.0.0.1:2181):o.a.z.ClientCnxn$SendThread@1427] - Session establishment complete on server /127.0.0.1:2181, session id = 0x10006aaf4950007, negotiated timeout = 30000

WATCHER::

WatchedEvent state:SyncConnected type:None path:null zxid: -1
[zk: 127.0.0.1:2181(CONNECTED) 0] 
2026-03-31 10:33:39,137 [myid:] - INFO  [main:o.a.z.u.ServiceUtils@45] - Exiting JVM with code 0
$

@PDavid
Copy link
Copy Markdown
Contributor Author

PDavid commented Mar 31, 2026

It seems org.apache.zookeeper.server.ServerCnxnFactoryTest.testShedConnections_SmallPercentageRoundsToZero{FactoryType}[2] failed in the PR build.

org.opentest4j.AssertionFailedError: 1% of 1 connection should round to 0 ==> expected: <0> but was: <1>
	at org.apache.zookeeper.server.ServerCnxnFactoryTest.testShedConnections_SmallPercentageRoundsToZero(ServerCnxnFactoryTest.java:106)

This test was added very recently, maybe it is flakey?

EDIT: I executed this test locally multiple times and it did not fail.

@anmolnar anmolnar merged commit 6c4fabf into apache:master Apr 9, 2026
16 checks passed
asf-gitbox-commits pushed a commit that referenced this pull request Apr 9, 2026
…D) is pressed

Reviewers: ctubbsii, kezhuw
Author: PDavid
Closes #2369 from PDavid/ZOOKEEPER-5021-cli-fix-eof-interrupt-2

(cherry picked from commit 6c4fabf)
Signed-off-by: Andor Molnar <andor@cloudera.com>
@anmolnar
Copy link
Copy Markdown
Contributor

anmolnar commented Apr 9, 2026

Merged to master and branch-3.9 branches. Thanks @PDavid !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants